home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / Macintosh Common Lisp Related / User Contributions / zebu v3.3.3 (LALR parser) / ZEBU-init.lisp < prev    next >
Encoding:
Text File  |  1994-09-12  |  5.7 KB  |  174 lines  |  [TEXT/ttxt]

  1. ; -*- mode:     CL -*- ----------------------------------------------------- ;
  2. ; File:         ZEBU-init.l
  3. ; Description:  Loading Zebu and the Compiler
  4. ; Author:       Joachim H. Laubsch
  5. ; Created:      19-May-92
  6. ; Modified:     Tue Aug  2 16:30:38 1994 (Joachim H. Laubsch)
  7. ; Language:     CL
  8. ; Package:      CL-USER
  9. ; Status:       Experimental (Do Not Distribute) 
  10. ; RCS $Header: $
  11. ;
  12. ; (c) Copyright 1992, Hewlett-Packard Company
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14. ; Revisions:
  15. ; RCS $Log: $
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17. ;; to use or compile Zebu, you must load this file first
  18.  
  19. ;; to load the Zebu Compiler, it has to be compiled
  20. ;;  To compile the Zebu Compiler load COMPILE-ZEBU.l
  21.  
  22. ;; zb:zebu to               "Load the Zebu Parser"
  23. ;; zb:zebu-compiler to      "Load the Zebu Compiler"
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  25. #-MCL(in-package "USER")
  26. #+MCL(in-package "CL-USER")
  27.  
  28. #-MCL
  29. (progn
  30.   (unless (find-package "CL-USER")
  31.     (defpackage "USER" (:nicknames "CL-USER")))
  32.   (in-package "CL-USER"))
  33.  
  34. (provide "ZEBU-init")
  35.  
  36. ;; edit the following form for your Lisp, and the directory where you keep Zebu
  37. (defvar *ZEBU-directory*
  38.   (make-pathname :directory
  39.          (pathname-directory
  40.           #-ALLEGRO *load-pathname*
  41.           #+ALLEGRO (merge-pathnames *load-pathname*
  42.                          *default-pathname-defaults*)))
  43.   )
  44.  
  45. (defvar *ZEBU-binary-directory*
  46.   (make-pathname :directory (append (pathname-directory *ZEBU-directory*)
  47.                     (list "binary"))))
  48.  
  49. (let ((*default-pathname-defaults* *ZEBU-directory*))
  50.   (load (merge-pathnames (make-pathname :name "zebu-package"
  51.                     :type "lisp"))))
  52.  
  53. (shadowing-import '(zb::zebu zb::zebu-compiler) (find-package "CL-USER"))
  54. (export '(zb::zebu zb::zebu-compiler) (find-package "ZB"))
  55.  
  56. #+LUCID(proclaim '(special zb:*zebu-version*))
  57. #-LUCID(declaim (special zb:*zebu-version*))
  58.  
  59. #+(or MCL Allegro)
  60. (defvar *load-binary-pathname-types* '("fasl"))
  61.  
  62. #+(and :SUN :LUCID)
  63. (defvar *load-binary-pathname-types* '("sbin"))
  64.  
  65. (defun zb:zebu ()
  66.   "Load the Zebu Parser"
  67.   (let ((binary-path (merge-pathnames
  68.               (make-pathname
  69.                :type (car *load-binary-pathname-types*))
  70.               *ZEBU-binary-directory*)))
  71.     (dolist (name '("zebu-aux"
  72.             "zebu-mg-domain"
  73.             "zebu-mg-hierarchy"
  74.             "zebu-loader"
  75.             "zebu-driver"
  76.             "zebu-actions"))
  77.       (require name
  78.            (merge-pathnames (make-pathname :name name) binary-path)))
  79.     (format t "~%;;; Zebu (Version ~a) loaded!" zb:*zebu-version*)
  80.     (values)))
  81.  
  82. (defun zb:zebu-compiler ()
  83.   "Load the Zebu Compiler"
  84.   (zb::zebu)
  85.   (push ':ZEBU *features*)
  86.   (let ((binary-path (merge-pathnames
  87.               (make-pathname
  88.                :type (car *load-binary-pathname-types*))
  89.               *ZEBU-binary-directory*)))
  90.     (dolist (name '("zebu-kb-domain" "zebu-regex"
  91.             "zebu-oset" "zebu-g-symbol" "zebu-loadgram"
  92.             "zebu-generator" "zebu-lr0-sets" "zebu-empty-st" "zebu-first"
  93.             "zebu-follow" "zebu-tables" "zebu-slr" "zebu-closure"
  94.             "zebu-lalr1" "zebu-dump" "zebu-compile"
  95.             "zebu-printers"))
  96.       (unless (member name *modules* :test #'string=)
  97.     (load (merge-pathnames (make-pathname :name name) binary-path))))
  98.     (zb::zebu-load-file (merge-pathnames
  99.              (make-pathname :name "zebu-mg" :type "tab")
  100.              *ZEBU-binary-directory*))
  101.     (format t "~%;;; Zebu Compiler (Version ~a) loaded!" zb:*zebu-version*)
  102.     (values)))
  103.  
  104. (defun zb:zebu-rr ()
  105.   "Load the rewrite-rule module"
  106.    (zb::zebu)
  107.   (let ((binary-path (merge-pathnames
  108.               (make-pathname
  109.                :type (car *load-binary-pathname-types*))
  110.               *ZEBU-binary-directory*)))
  111.     (dolist (name '("zebu-kb-domain" "zebu-tree-attributes"
  112.             "zebra-debug"))
  113.       (unless (member name *modules* :test #'string=)
  114.     (load (merge-pathnames (make-pathname :name name) binary-path))))
  115.     (values)))
  116.     
  117. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  118. ;; You may want to omit this and rather import only a subset of the 
  119. ;; symbols or use package "ZEBU" in another package than the CL-USER
  120. ;; package.
  121.  
  122. (use-package (find-package "ZEBU"))
  123.  
  124. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  125. ;;                               A few Examples
  126. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  127. #||
  128. ;; load the compiler
  129. (zb:zebu-compiler)
  130. (defvar *ZEBU-test-directory*
  131.   (make-pathname :directory (append (pathname-directory *ZEBU-directory*)
  132.                     (list "test"))))
  133. (defvar *ZEBU-test-binary-directory*
  134.   (make-pathname :directory (append (pathname-directory *ZEBU-test-directory*)
  135.                     (list "binary"))))
  136.  
  137. (progn
  138.   #+LUCID
  139.   (or (probe-file *ZEBU-test-binary-directory*)
  140.       (shell (format nil "mkdir ~a" (namestring *ZEBU-test-binary-directory*))))
  141.   #+MCL
  142.   (create-file *ZEBU-test-binary-directory* :if-exists nil)
  143.   )
  144.  
  145. (zebu-compile-file (merge-pathnames
  146.             (make-pathname :name "ex1" :type "zb") *ZEBU-test-directory*)
  147.            :output-file
  148.            (merge-pathnames
  149.             (make-pathname :name "ex1" :type "tab")
  150.             *ZEBU-test-binary-directory*))
  151.  
  152. (zb:zebu-load-file (merge-pathnames
  153.             (make-pathname :name "ex1" :type "tab")
  154.                     *ZEBU-test-binary-directory*))
  155.  
  156. (zb:zebu)
  157. (zebu-load-file (merge-pathnames
  158.          (make-pathname :name "ex1" :type "tab")
  159.                  *ZEBU-test-binary-directory*))
  160. (setq zebu:*current-grammar* (zb:find-grammar "ex1"))
  161. (list-parser '(1 "+" 1))
  162. (equal (read-parser "1 + 1") (list-parser '(1 "+" 1)))
  163. (read-parser "1.0 * 1")
  164. (read-parser "1.0 * 1/33")
  165. (read-parser "1.0 * a1")
  166. (read-parser "1.0 * .3")
  167. (read-parser "1.0 * 12.3")
  168.  
  169. ||#
  170.  
  171. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  172. ;;                             End of ZEBU-init.l
  173. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  174.